<?php
class Db_user_page_static  extends Model_Db_Core {

	private $con = null;
	private $statistic = null;
	private $username;

	function __construct(){

	}

	public function checkStaticAccess($staticId,$user_id){		
		$filter  = array('user_id'=> $user_id,'id'=> $staticId);
	    $select  = array();
	    
	    parent::getSQLResult(__CLASS__,$filter,$select);
	    $this->statistic = parent::result();

	    return $this->statistic;
	}

	public function getStaticPage($staticId = NULL ,$user_id){	
		$sql = 'Select * from user_page_static usp, user_page_explorer upe WHERE usp.user_id = upe.user_id and usp.id='.$staticId.' and usp.id = upe.static_nr and upe.user_id ='.$user_id.' LIMIT 0,1';
	
		parent::setSqlManuel($sql);
	    $this->statistic = parent::result();
	    		
		return $this->statistic;		
	}

	public function updateStaticPage($id,$user_id,$data){
		$i = 0;
		$count = count($data)-2;
		$what = "";
		
		foreach ($data as $tuppel => $value){
			if(!preg_match(DONT_TOUCH,$tuppel)){
				$what .= $tuppel."='".$value."' ";
				if($count > $i)
				{
					$what .= ", ";
				}
			}			
			$i++;
		}
		$update = 'UPDATE user_page_static, user_page_explorer SET '.$what.' WHERE user_page_static.id= '.$id.' and user_page_static.id=user_page_explorer.static_nr and user_page_static.user_id='.$user_id;

		parent::setSqlManuel($update);		
		
		return true;
	}
	public function insertStaticPage($user_id,$data){
		
		if($data['url'] == ''){
			return false;
		}
		
		if($data){
			if(!$data['meta_robots']){
				$data['meta_robots'] = 1;
			}
			$update ="INSERT INTO user_page_static (
                    `id` ,
                    `user_id` ,
                    `text` ,
                    `meta_robots` ,
                    `meta_beschreibung` ,
                    `meta_keys`
                    )
                    VALUES (
                    NULL ,  ".$user_id.",  '".$data['text']."',  ".$data['meta_robots'].",  '".$data['meta_beschreibung']."',  '".$data['meta_keys']."')";
			
			parent::setSqlManuel($update);		
			$Id = parent::getLastInsertId();
			
			$update = "INSERT INTO  user_page_explorer (
                        `id` ,
                        `user_id` ,
                        `name` ,
                        `slogen` ,
                        `titel` ,
                        `url` ,
                        `aktiv` ,
                        `zugriff` ,
                        `passwort` ,
                        `navi` ,
                        `navi_posi` ,
                        `main_flag` ,
                        `modul_nr` ,
                        `static_nr`
                        )
                        VALUES (
                        NULL ,  ".$user_id.",  '".$data['name']."', '".$data['slogen']."',  '".$data['titel']."',  '".$data['url']."',  ".$data['aktiv'].", ".$data['zugriff'].",'".$data['passwort']."',".$data['navi'].",99,".$data['main_flag'].",  0,  ".$Id.")";        

			parent::setSqlManuel($update);			
		}
	}
	public function delStaticPage($id, $user_id){
		$sql = 'Delete From user_page_static where user_page_static.id='.$id.' and user_page_static.user_id='.$user_id;

		parent::setSqlManuel($sql);
	}
	public function getNavi($topnavi,$middel){
	    
	    $topNavi_navi = array(	"Neuigkeiten" =>array("/",
	    							array("Nachrichten" => array("/mailbox"))),
	                          	"Webseiten" =>array("/Explorer",
	    							array("Module"       =>array("/modul"),
	                                      "Deine Seiten" =>array("/Explorer"),
	                                      "Layouts"      =>array("/Design"))),
	                     		"Meine Daten" => array("/useredit",array()),
	                     		"Statistic" => array("/Explorer",array())
	                    ); 
	    $final = array();         
	    foreach ($topNavi_navi as $key => $navi){
	        if($key != $topnavi){
	            $topNavi_navi[$key][1] = array();
	            $final[$key] = $topNavi_navi[$key];
	        }else{	            
	            $final[$key] = $topNavi_navi[$key];
	             foreach ($final[$key][1] as $key1 => $navi1){
	                  if($key1 != $middel){	    
	                     $final[$key][1][$key1][1] = array();                  
	                  }
	             }
	        }
	    }
	    return $final;	    
	}
}

?>